import Vue from 'vue';
import App from './App.vue';
import router from './router';
import ElementUI from 'element-ui';
/* iconfont */
import '@/assets/iconfont/iconfont.css'
import VueI18n from 'vue-i18n';
import {msgs} from './components/common/i18n';
import 'dhtmlx-gantt/codebase/dhtmlxgantt.css'
import 'element-ui/lib/theme-chalk/index.css'; // 默认主题
import btnPermissionUtil from './utils/btnPermissionUtil'

import mavonEditor from 'mavon-editor'
import 'mavon-editor/dist/css/index.css'
// import './assets/css/theme-green/index.css'; // 浅绿色主题
import './assets/css/icon.css';
import './components/common/directives';
import 'babel-polyfill';
import XEUtils from 'xe-utils'
import VXETable from 'vxe-table'
import 'vxe-table/lib/index.css'
import zhCN from 'vxe-table/lib/locale/lang/zh-CN'
import store from './store';
import '@/styles/app.css';
import {getToken} from '@/utils/cookie';
// import mavonEditor from 'mavon-editor';
// import 'mavon-editor/dist/css/index.css';
import './validates/validate'

Vue.use(mavonEditor);
Vue.use(mavonEditor);
import {mockData} from './mock/mockData.js'
import './directives/index'
import request from "@/utils/request";
import '@/utils/utilJs'
import {ElementTiptapPlugin} from 'element-tiptap';
import 'element-ui/lib/theme-chalk/index.css';
import 'element-tiptap/lib/index.css';

// import VueMarkdownEditor from '@kangc/v-md-editor';
// import '@kangc/v-md-editor/lib/style/base-editor.css';
// import vuepressTheme from '@kangc/v-md-editor/lib/theme/vuepress.js';
// import createTodoListPlugin from '@kangc/v-md-editor/lib/plugins/todo-list/index.js';
// VueMarkdownEditor.use(vuepressTheme);
// VueMarkdownEditor.use(createTodoListPlugin())
// Vue.use(VueMarkdownEditor);


Vue.use(ElementTiptapPlugin, {lang: "zh", spellcheck: true});
Vue.config.productionTip = false;
Vue.use(VueI18n);
Vue.use(ElementUI, {
    size: 'small'
});
Vue.use(VXETable)
import vSelectPage from 'v-selectpage';

Vue.use(vSelectPage, {
    dataLoad: function (vue, data, params) {
        const {pageSize, pageSizeName, pageNumber, pageNumberName, url, method, ...rest} = params
        let query = {...rest}
        query[pageSizeName] = pageSize
        query[pageNumberName] = pageNumber
        if (rest.searchKey === undefined) {
            return request({
                url: url,
                method: method,
                params: query
            })
        } else {
            return request({
                url: url,
                method: method,
                params: query
            })
        }
    }
});
// ...
import VXETablePluginElement from 'vxe-table-plugin-element'
import 'vxe-table-plugin-element/dist/style.css'
// ...

VXETable.use(VXETablePluginElement)
const messages = {
    zh_CN: {
        ...zhCN,
        ...msgs
    }
}

const i18n = new VueI18n({
    locale: 'zh_CN',
    messages,
})
// **************** （注意：该全局变量仅用于开发环境调试） ****************
// if (process.env.NODE_ENV === 'development') {
//     window.XEUtils = XEUtils
// }
window.XEUtils = XEUtils

mockData()

// 屏蔽同一路由多次跳转报错
const VueRouterPush = router.push
router.push = function (to) {
    return VueRouterPush.call(this, to).catch(() => {
    })
}
//注册filter
// Object.keys(filters).forEach(key => Vue.filter(key, filters[key]))
Vue.prototype.btnPermissionUtil = btnPermissionUtil

//使用钩子函数对路由进行权限跳转
router.beforeEach((to, from, next) => {
    document.title = `${to.meta.title} | pms`;
    const token = getToken();
    if (!token && to.path !== '/view/login') {
        next('/view/login');
    } else {
        if (!store.getters.btnPermission) {
          store.dispatch('GetBtnPermissions');
        }
        if (to.path !== '/view/login') {
            if ((!store.state.sys.Dictionary || !store.state.sys.Dictionary.length)) {
                store.dispatch('GetDictionary');
            }
            if ((!store.state.user.users || !store.state.user.users.length)) {
                store.dispatch('GetUsers');
            }
        }
        // 简单的判断IE10及以下不进入富文本编辑器，该组件不兼容
        if (navigator.userAgent.indexOf('MSIE') > -1 && to.path === '/editor') {
            Vue.prototype.$alert('vue-quill-editor组件不兼容IE10及以下浏览器，请使用更高版本的浏览器查看', '浏览器不兼容通知', {
                confirmButtonText: '确定'
            });
            next('/view/mainpage');
        } else {
            next();
        }
    }
});

new Vue({
    router,
    i18n,
    store,
    render: h => h(App)
}).$mount('#app');
